#include <iostream>
using namespace std;

class Shape {  // 定义一个形状类
 private:
  int id_;

 public:
  Shape(int id) {
    cout << "==> Shape构造函数" << endl;

    id_ = id;
  }
  ~Shape() { cout << "==> Shape析构函数" << endl; }

  int getID() { return id_; }

  void setID(int ID) {
    cout << "==> 设置新的ID" << endl;
    id_ = ID;
  }

  int getArea() {
    cout << "==> 在Shape类里：getArea" << endl;
    return 0;
  }
};

class Circle : public Shape {
 private:
  int r;
  const float pi = 3.14159;

 public:
  Circle(int ID, int R) : Shape(ID) {
    cout << "==> 圆构造函数" << endl;
    r = R;
  }

  ~Circle() { cout << "==> 圆析构函数" << endl; }
  int getR() { return r; }
  void setR(int R) { r = R; }

  double getArea() {
    cout << "==> 计算圆的面积" << endl;
    cout << pi << " " << r << endl;
    return pi * r * r;
  }
};

class Rectangle : Shape {
 private:
  int h, w;

 public:
  Rectangle(int ID, int h_, int w_) : Shape(ID) {
    cout << "==> 矩形构造函数" << endl;
    w = w_;
    h = h_;
  }
  ~Rectangle() { cout << "==> 矩形析构函数" << endl; }
  int geth() { return h; }
  int getw() { return w; }
  void seth(int h_) { h = h_; }
  void setw(int w_) { w = w_; }
  int getArea() {
    cout << "==> 计算矩形的面积" << endl;
    return w * h;
  }
};
 
int main() {
  Shape s(1);            // 1表示ID
  Circle c(2, 4);        // 4表示半径，2表示ID
  Rectangle r(3, 4, 5);  // 4和5表示长和宽，3表示ID
  cout << "Shape的面积" << s.getArea() << endl;
  cout << "Circle的面积" << c.getArea() << endl;
  cout << "Rectangle的面积" << r.getArea() << endl;
}
